<template>
    <div class="page-container" style="height: 100%;padding:10% 30% 0 30%;">
        <div style="border:1px solid #eee;border-radius: 6px;">
            <div style="padding: 10px;text-align: center">修改密码</div>
            <div style="padding:20px;">
                <el-row :gutter="20">
                    <el-col :span="8"><span class="padding:7px;">用户名：</span></el-col>
                    <el-col :span="16">
                        <el-input v-model="userName" readonly></el-input>
                    </el-col>
                </el-row>
            </div>
            <div style="padding:20px;">
                <el-row :gutter="20">
                    <el-col :span="8"><span class="padding:7px;">密码：</span></el-col>
                    <el-col :span="16">
                        <el-input v-model="password" placeholder="请输入密码"></el-input>
                    </el-col>
                </el-row>
            </div>
            <div style="padding:6px 20px;text-align: right;color:red;">密码不少于6位数</div>
            <div style="padding:20px;">
                <el-row :gutter="20">
                    <el-col :span="8"><span class="padding:7px;">再次确认密码：</span></el-col>
                    <el-col :span="16">
                        <el-input v-model="agePassword" placeholder="请输入密码"></el-input>
                    </el-col>
                </el-row>
            </div>
            <div style="padding:20px;text-align: center;">
                <el-button type="primary" @click="submitMethod">提交</el-button>
                <el-button type="info" @click="()=>{this.$router.push('/')}">返回</el-button>
            </div>
        </div>
    </div>
</template>

<script>
    import api from '@/api/apis';
    export default {
        name: "setPassword",
        data(){
            return {
                password:'',
                agePassword:'',
                userName:''
            }
        },
        created() {
            let userInfo=JSON.parse(window.localStorage.getItem('userInfo'));
            this.userName=userInfo.account;
        },
        methods:{
            submitMethod(){
                if(this.password.trim().length<6){
                     this.$message.error('密码长度不够');return;
                }
                if(this.password.trim() !== this.agePassword.trim()){
                    this.$message.error('两次输入密码不一致请重新输入');return;
                }

                this.$http.post(api.SET_PASSWORD,{password:this.password})
                    .then((res) => {
                        console.log('判断是否正确',res)
                        if (res.code == 1) {
                            this.$message.success('修改成功');
                            setTimeout(()=>{
                                window.sessionStorage.removeItem('userName')
                                window.sessionStorage.removeItem('jqzxUserId')
                                this.$router.push('/login');
                            },1000)
                        }
                    })

            }
        }
    }
</script>

<style scoped>

</style>
